package test;// write your code here
import java.util.*;
public class Main {
    
    public static void numberRoot(int x){
        int number = x;
        while((number/10)!=0){
            //得到number的每一位数字相加
            int ret = number;
            int sum = 0;
            while(ret!=0){
                sum+=(ret%10);
                if(ret==0)break;
                ret/=10;
            }
            number = sum;
            if(number==0){
                number = 0;
                break;
            }
        }
        System.out.println(number);
    }
    
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int x = scan.nextInt();
            numberRoot(x);    
        }
    }
}